#include "cclockitem.h"

#include <buola/image/cimage.h>
#include <buola/image/cfont.h>
#include <buola/image/cgc.h>
#include <buola/datetime/cdatetime.h>

namespace buola { namespace bdesktop {

CClockItem::CClockItem()
{
}

CClockItem::~CClockItem()
{
}

double CClockItem::GetWidth()
{
    return CFont::GetStock(L"nicetitle")->GetWidth(L"SSS 00:00")+16;
}

void CClockItem::Draw(CGC *pGC)
{
    pGC->SetStockFont(L"nicetitle");
    CPoint lPos(mPos.l+8,(mPos.t+mPos.b)/2-2);
    CDateTime lTime(CCalendarClock::now());
    std::wstring lString=lTime.Date().GetShortWeekdayText();
    lString+=' ';
    lString+=lTime.Time().GetHourMinText();
    pGC->SetSourceColor(CColor(0.2,0.2,0.2,1.0));
    pGC->DrawText(lPos+1,lString,NFont::VCENTER);
    pGC->SetSourceColor(CColor(0.9,0.9,0.9,1.0));
    pGC->DrawText(lPos,lString,NFont::VCENTER);

    if(!mTimer)
    {
        mTimer=new CTimer(std::chrono::seconds(1));
        mTimer->sTimer.Connect(&CClockItem::OnTimer,this);
    }
    mTimer->SetInterval(std::chrono::seconds(61-lTime.Time().Sec()),true);
}

void CClockItem::OnClick(gui::CMouseEvent*)
{
}

void CClockItem::OnTimer()
{
    if(mBar)
        mBar->Refresh();
}

/*namespace bdesktop*/ } /*namespace buola*/ }
